gusucode.com > 各种VC自绘控件源码程序 > 各种VC自绘控件源码/code/SkinControls(自绘MFC基本控件 )/SkinControls/SkinControls/SkinListBox.cpp
#include "stdafx.h" #include "SkinListBox.h" IMPLEMENT_DYNAMIC(CSkinListBox, CListBox) BEGIN_MESSAGE_MAP(CSkinListBox, CListBox) END_MESSAGE_MAP() CSkinListBox::CSkinListBox() { } CSkinListBox::~CSkinListBox() { } void CSkinListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { lpMeasureItemStruct->itemHeight = 20; } void CSkinListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); COLORREF crOldTextColor = pDC->GetTextColor(); COLORREF crOldBkColor = pDC->GetBkColor(); CRect rcItem = lpDrawItemStruct->rcItem; if (lpDrawItemStruct->itemState&ODS_FOCUS) pDC->FillSolidRect(&rcItem,RGB(40,82,144)); else pDC->FillSolidRect(&rcItem, crOldBkColor); CPen pen; pen.CreatePen(PS_SOLID, 1, RGB(115,137,150)); pDC->SelectObject(&pen); pDC->MoveTo(rcItem.left, rcItem.bottom-1); pDC->LineTo(rcItem.right, rcItem.bottom-1); CString strText; if (GetCount() > 0) strText = (LPTSTR)GetItemData(lpDrawItemStruct->itemID); pDC->DrawText(strText, &rcItem, DT_LEFT|DT_VCENTER|DT_SINGLELINE); }